/*
* @Author: majingyu
* @Date:   2017-05-23 16:34:44
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-08-01 22:58:02
*/
import $ from 'jQuery';
import 'css/common/tips.less';


export const toast = (message, delayTime) => {
    let $toast  = $('.iss-toast'), 
        msg     = message ? message : '出错啦',
        delay   = /\d/.test(delayTime) ? delayTime : 2000,
        tpl     = '<div class="iss-toast"><span class="text"></span></div>';
    
    if ($toast.length) {
        $toast.remove();
    }
    $toast = $(tpl).appendTo('body');
    $toast.find('.text').text(msg);

    // 定时取消
    setTimeout(function() {
        $toast.remove()
    }, delay);
}
export const confirm = (param) => {
    let $conform    = $('.iss-conform'),
        title       = param.title,
        mess        = param.message?param.message: '确定进行此操作吗？',
        tpl         = '<div class="view-remark"><div class="iss-conform"><p class="title-tip"></p><p class="content-tip"></p><div class="option-btn"></div></div></div>',
        cancelText  = params.cacal?(param.cancelText || '取消'):'',
        confirmText = param.confirmText|| '确定',
        cancel      =param.cancel || true,
        btns        = cancel?"<span class='cancel-btn'>"+cancelText+"</span><span class='confirm-btn'>"+confirmText+"</span>": "<span class='only-confirm'>"+confirmText+"</span>"

    if($conform .length){
        $conform.remove();
    }
    $conform  = $(tpl).appendTo('body');
    $conform.find('.title-tip').text(param.title);
    $conform.find('.content-tip').html(mess);
    $conform.find('.option-btn').html(btns);
    $('.cancel-btn').click(function(){
        if(param.cancelCallback){
           param.cancelCallback(); 
        }
        $conform.remove();
    })
    $('.confirm-btn, .only-confirm').click(function(){
        if(param.confirmCallback){
            param.confirmCallback(); 
        }
         
        $conform.remove();
    });
}